#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: pipeline_new.py 
@version:
@time: 2022/05/31 
"""
from TapClientCore.T04_logic.DagNew.DAG.dag_new import DAGNEW


class PipelineNew:

    def __init__(self, name, setting):
        self._name = name
        self._current_node = None
        self._source_node = None
        self._dataflow_type = setting.pop('mappingTemplate')
        self._setting = setting
        self._dag = DAGNEW()

    def _read_from(self, node):
        # 当前节点
        self._current_node = node
        return self

    def readFrom(self, source_node):
        # 当前源节点
        self._source_node = source_node
        return self._read_from(source_node)

    def cloneTo(self, target, relations):
        self._dag.clone_edge(self._current_node, target, relations)
        # 当前节点更新
        return self._read_from(target)

    def syncTo(self, target, relations):
        self._dag.sync_edge(self._current_node, target, relations)
        # 当前节点更新
        return self._read_from(target)

    # 构造出的任务 payload
    @property
    def pipelines(self):
        return {
            'name': self._name,
            'description': '',
            'status': 'paused',
            'executeMode': 'normal',
            'category': '数据库克隆',
            'stopOnError': False,
            'mappingTemplate': self._dataflow_type,
            'emailWaring': {
                'edited': True,
                'started': False,
                'error': True,
                'paused': False
            },
            'stages': self._dag.stages,
            'setting': self._setting
        }
